package Thread;
class Counter{
    public int count;
    public void add(){
        synchronized (this){
            count++;
        }
    }
    public static void A(){
        synchronized (Counter.class){

        }
    }

}
public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter=new Counter();
        Thread thread1=new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                synchronized (counter){
                    counter.add();
                }

            }
        });
        Thread thread2=new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                synchronized (counter){
                    counter.add();
                }
            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
    }
}
